<?

/* @var $form SettingForm */
/* @var $settings Settings */

$out=array();
foreach ($form as $name => $field){
	if (!$field->isHidden() && $name!="id" && $name!="_csrf_token"){
		if (empty($filter) || $filter=="definitions"){
			$cGroup=$form->getFieldsGroup($field);

			$widget=$field->getWidget();
			$out[$name]=array(
				"name" 				=> $name,
				"title"				=> $widget->getLabel(),
				"group"				=> $cGroup,
				"description" 		=> $widget->getAttribute("description"),
			);

			$type="unknown";
			if ($widget instanceOf sfWidgetFormInputText){
				$type="text";
			}else if ($widget instanceOf sfWidgetFormChoice){
				$type="select";
				$choices=$widget->getChoices();
				$out[$name]["options"]=array_keys($choices);
				$out[$name]["optionTitles"]=array_values($choices);
			}else if ($widget instanceOf sfWidgetFormInputFile){
				$type="file";
			}

			$out[$name]["type"]=$type;



			 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
	    	///  Additional Parameters   ////////////////////////////////////////////////////////////////////////////////

			// unit...
			if ($widget->getAttribute("unit") != "") $out[$name]["unit"]=$widget->getAttribute("unit");

			// min and max...
			if ($widget->getAttribute("min") != "") $out[$name]["min"]=$widget->getAttribute("min");
			if ($widget->getAttribute("max") != "") $out[$name]["max"]=$widget->getAttribute("max");

			// renderType...
			if ($widget->getAttribute("renderType")!=""){
				$out[$name]["renderType"]=$widget->getAttribute("renderType");
			}else if ($form->getValidator($name) instanceOf sfValidatorInteger || $form->getValidator($name) instanceOf sfValidatorNumber){
				$out[$name]["renderType"]="number";
			}

			// renderGroup...
			if ($widget->getAttribute("renderGroup")!=""){
				$out[$name]["renderGroup"]=$widget->getAttribute("renderGroup");
			}

			// css connection
			if ($widget->getAttribute("cssconn")!=""){
				$out[$name]["cssconn"]=$widget->getAttribute("cssconn");
			}



			 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
	    	///  Default Value   ////////////////////////////////////////////////////////////////////////////////////////

			if ($form->getDefault($name)!=""){
				$out[$name]["default"]=$form->getDefault($name);
			}

		}

		if (empty($filter) || $filter=="values"){
			if ($settings->getValue($name)!=""){
				$out[$name]["value"]=$settings->getValue($name);
			}
		}
	}
}
echo json_encode($out);



